﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using sqlserverextensions.Helper;


    public partial class UserDefinedFunctions
    {
        [Microsoft.SqlServer.Server.SqlFunction]
        public static SqlString SubStr(SqlString value, SqlInt16 startIndex)
        {
            Int16 errSeverity = 16;

            try
            {
                if (value.IsNull)
                    value = "";

                return value.Value.Substring(startIndex.Value - 1);
            }
            catch (Exception ex)
            {
                ExceptionHelper.EvaluateException(ex, errSeverity);
                return null;
            }

        }
    }

